#include"figure.h"
#include <stdlib.h>

		//////////////////
		/* CONSTRUCTORS */
		//////////////////

Figure::Figure(){};
Figure::Figure(bool _color, int x, int y, char _letter):color(_color),letter(_letter), count(0){
        position.x = x;
        position.y = y;
};

Pawn::Pawn(bool _color, int x, int y):Figure(_color, x, y, 'p'){};
Rook::Rook(bool _color, int x, int y):Figure(_color, x, y, 'r'){};
Knight::Knight(bool _color, int x, int y): Figure(_color, x, y, 'n'){};
Bishop::Bishop(bool _color, int x, int y): Figure(_color, x, y, 'b'){};
Queen::Queen(bool _color, int x, int y): Figure(_color, x, y, 'q'){};
King::King(bool _color, int x, int y):Figure(_color, x, y, 'k'){};
		
		/////////////////////////
		/* SETTERS AND GETTERS */
		/////////////////////////

int Figure::get_x() const{ return position.x;}
int Figure::get_y() const{ return position.y;}
pos Figure::get_position() const{ return position;}
void Figure::set_position(int x, int y){
        position.x = x;
        position.y = y;
}

bool Figure::get_color() const{ return color;}
void Figure::set_color(bool _color){ color = _color;}

char Figure::get_letter() const{ return (color == true)? letter : letter-32;}

void Figure::inc(){ count++; }

		//////////////////
		/* VIRTUAL MOVE */
		//////////////////

bool Knight::move(pos new_position) const{
	return ((abs(new_position.x-position.x)==2 && abs(new_position.y-position.y)==1)||
					(abs(new_position.x-position.x)==1 && abs(new_position.y-position.y)==2))? true : false;
}

bool Bishop::move(pos new_position) const{
	return (abs(new_position.x - position.x) == abs(new_position.y - position.y))? true : false;
}

bool Rook::move(pos new_position) const{
	return (abs(new_position.x-position.x)==0 || abs(new_position.y-position.y)==0)? true : false;
}

bool Pawn::move(pos new_position) const{
	int y_shft = new_position.y - position.y;
	int x_shft = new_position.x - position.x;
	return (abs(x_shft)<=1 && ((y_shft == 2*color-1) || (count == 0 && y_shft == 2*(2*color - 1))));	
}

bool Queen::move(pos new_position) const{
	return (abs(new_position.x - position.x) == abs(new_position.y - position.y) ||
					abs(new_position.x-position.x)==0 || abs(new_position.y-position.y)==0)? true : false;
}

bool King::move(pos new_position) const{
	int x_shft = abs(new_position.x - position.x);
	int y_shft = abs(new_position.y - position.y);
	return (x_shft <=1 && y_shft <=1)? true: false;
}
